
import numpy as np
from sklearn.naive_bayes import GaussianNB
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

clf = GaussianNB()
iris = load_iris()
data_tr, data_te, label_tr, label_te = train_test_split(iris.data, iris.target, test_size=0.2)
clf.fit(data_tr, label_tr)

print("data_tr")
print(data_tr)
print("label_tr")
print(label_tr)

pre = clf.predict(data_te)
acc = sum(pre == label_te) / len(pre)

print("预测值")
print(pre)
print("label_te")
print(label_te)
print("预测精度")
print(acc)


